<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改用户')" />
	<th:block th:include="include :: select2-css" />
    <style type="text/css">
        .noBorder {
            width: 100%;
            height: 100%;
            border: none;
            font-size: 15px;
        }

        .table th {
            text-align: center;
            font-size: 15px;
            height: 40px;
        }

        label.error {
            position: absolute;
            right: 40px;
            top: 15px;
            color: #ef392b;
            font-size: 15px;
            z-index:99;
        }
    </style>
</head>
<body>
    <div class="main-content">
        <form class="form-horizontal" id="form-user-edit" th:object="${user}">
            <input name="userId"  type="hidden"  th:field="*{userId}" />
			<input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeId"/>
            <h4 class="form-header h4">基本信息</h4>

            <div class="row" style="margin-top: 40px;">
                <div class="col-sm-10 text-center">
                    <div class="table-responsive" style="margin-left: 30px;">
                        <table class="table" border="1" bordercolor="black" align="center" >
                            <caption><strong><h2 align="center">党员信息</h2></strong></caption><br/>
                            <tbody>
                            <tr align="center">
                                <th>登录账号</th>
                                <td colspan="2">
                                    <input id="loginName" name="loginName" type="text" class="noBorder" th:field="*{loginName}" readonly >
                                </td>
                                <th>登录密码</th>
                                <td colspan="2">
                                    <input  class="noBorder" type="password"
                                           th:value="${@config.getKey('sys.user.initPassword')}" readonly>
                                </td>
                            </tr>
                            <tr align="center">
                                <th>姓名</th>
                                <td>
                                    <input name="userName" type="text" class="noBorder" th:field="*{userName}" required>
                                </td>
                                <th align="center">性别</th>
                                <td>
                                    <input name="sex" type="text" class="noBorder"  th:field="*{sex}" required>
                                </td>
                                <th align="center">民族</th>
                                <td>
                                    <input name="nation" type="text" class="noBorder"  th:field="*{nation}">
                                </td>
                            </tr>
                            <tr align="center">
                                <th>联系电话</th>
                                <td colspan="5">
                                    <input id="phonenumber" name="phonenumber" type="text" class="noBorder" th:field="*{phonenumber}"  required>
                                </td>
                            </tr>
                            <tr align="center">
                                <th>出生年月</th>
                                <td>
                                    <input name="year" type="text" class=" noBorder" th:field="*{year}"   required>
                                </td>
                                <th>家庭出生</th>
                                <td>
                                    <input name="family" type="text" class="noBorder" th:field="*{family}" >
                                </td>
                                <th>籍贯</th>
                                <td>
                                    <input name="place" type="text" class="noBorder" th:field="*{place}" >
                                </td>
                            </tr>
                            <tr align="center">
                                <th rowspan="2">文化程度</th>
                                <th>原有</th>
                                <td><input name="oldLevel" type="text" class="noBorder" th:field="*{oldLevel}"  required></td>
                                <th rowspan="2">职务</th>
                                <th>党内</th>
                                <td><input name="partyPost" type="text" class="noBorder" th:field="*{partyPost}" ></td>
                            </tr>
                            <tr align="center">
                                <th>现有</th>
                                <td><input name="newLevel" type="text" class="noBorder" th:field="*{newLevel}" ></td>
                                <th>行政</th>
                                <td><input name="adminPost" type="text" class="noBorder" th:field="*{adminPost}" ></td>
                            </tr>
                            <tr align="center">
                                <th>参加工作时间</th>
                                <td>
                                    <input name="workTime" type="text" class="noBorder" required th:field="*{workTime}" >
                                </td>
                                <th>职称</th>
                                <td>
                                    <input name="jobName" type="text" class="noBorder" th:field="*{jobName}"  required>
                                </td>
                                <th>介绍人</th>
                                <td>
                                    <input name="refer" type="text" class="noBorder" th:field="*{refer}" >
                                </td>
                            </tr>
                            <tr align="center">
                                <th>入党时间</th>
                                <td>
                                    <input name="partyTime" type="text" class="noBorder time-input"  th:field="*{partyTime}"   required>
                                </td>
                                <th>转正时间</th>
                                <td>
                                    <input name="positiveTime" type="text" class="noBorder time-input"  th:field="*{positiveTime}"  required>
                                </td>
                                <th>科室</th>
                                <td>
                                    <input name="office" type="text" class="noBorder" th:field="*{office}"  required>
                                </td>
                            </tr>
                            <tr align="center">
                                <th>身份证号</th>
                                <td colspan="2">
                                    <input name="idCard" type="text" class="noBorder"  th:field="*{idCard}"  required>
                                </td>
                                <th>所属党支部</th>
                                <td colspan="2">
                                    <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" th:field="*{dept.deptName}"
                                           class="noBorder" required>
                                </td>
                            </tr>
                            <tr>
                                <th>角色</th>
                                <td colspan="5" style="text-align: left">
                                    <label th:each="role:${roles}" class="check-box" style="font-size: 15px;color: #0C0C0C;">
                                    <input name="role" type="checkbox" th:value="${role.roleId}" th:text="${role.roleName}" th:checked="${role.flag}" th:disabled="${role.status == '1'}">
                                    </label>
                                </td>
                            </tr>
                            <tr align="center">
                                <th>备注</th>
                                <td colspan="5">
                                    <textarea name="remark" type="text" class="noBorder" rows="3" th:field="*{remark}" ></textarea>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: select2-js" />
	<script type="text/javascript">
        var prefix = ctx + "system/user";
        
        $("#form-user-edit").validate({
        	onkeyup: false,
        	rules:{
        		email:{
                    email:true,
                    remote: {
                        url: prefix + "/checkEmailUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	"userId": function() {
                                return $("#userId").val();
                            },
                			"email": function() {
                                return $.common.trim($("#email").val());
                            }
                        },
                        dataFilter: function (data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        		phonenumber:{
        			isPhone:true,
                    remote: {
                        url: prefix + "/checkPhoneUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	"userId": function() {
                        		return $("#userId").val();
                            },
                			"phonenumber": function() {
                                return $.common.trim($("#phonenumber").val());
                            }
                        },
                        dataFilter: function (data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
        	},
        	messages: {
        		"email": {
                    remote: "Email已经存在"
                },
        		"phonenumber":{
                	remote: "手机号码已经存在"
        		}
            },
            focusCleanup: true
        });
        
        function submitHandler() {
	        if ($.validate.form()) {
	        	var data = $("#form-user-edit").serializeArray();
	        	var status = $("input[id='status']").is(':checked') == true ? 0 : 1;
	        	var roleIds = $.form.selectCheckeds("role");
	        	var postIds = $.form.selectSelects("post");
	        	data.push({"name": "status", "value": status});
	        	data.push({"name": "roleIds", "value": roleIds});
	        	data.push({"name": "postIds", "value": postIds});
	        	$.operate.saveTab(prefix + "/edit", data);
	        }
	    }

        /*用户管理-修改-选择部门树*/
        function selectDeptTree() {
        	var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
		    var options = {
				title: '选择部门',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
    			var body = layer.getChildFrame('body', index);
    			$("#treeId").val(body.find('#treeId').val());
    			$("#treeName").val(body.find('#treeName').val());
    			layer.close(index);
			}
		}

		$(function() {
            $('#post').select2({
                placeholder: "请选择岗位",
                allowClear: true
            });
        })
    </script>
</body>
</html>